package com.servlet.news;

import com.dao.NewsDao;
import com.dao.NewsInfo;
import com.entity.News;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author admin
 */
@WebServlet(name = "NewsUpdateServlet",urlPatterns = "/NewsUpdateServlet.filter")
public class NewsUpdateServlet extends HttpServlet {

    private NewsDao newsDao = new NewsInfo();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String n_id = request.getParameter("n_id");
        String n_title = request.getParameter("n_title");
        String u_name = request.getParameter("u_name");
        String t_name = request.getParameter("t_name");
        String n_content = request.getParameter("n_content");
        System.out.println(n_id+n_title+u_name+t_name+n_content);
        try {
            boolean b = newsDao.updateNews(Integer.parseInt(n_id),n_title,u_name,t_name,n_content);
            if (b){
                System.out.println("新闻修改成功");
                response.sendRedirect(request.getContextPath()+"/NewsSelectAllServlet.filter");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
